--塵世棋路
local chenshiqilu = fk.CreateSkill {
    name = "mcdh_chenshiqilu",
    tags = {Skill.Switch}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

chenshiqilu:addEffect(fk.AfterCardsMove,{
    switch_skill_name = "mcdh_chenshiqilu",
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
            for _, move in ipairs(data) do
                if move.from == player.id then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                            local card = Fk:getCardById(info.cardId)
                            if player:getSwitchSkillState(self.name) == fk.SwitchYang and Fk:translate(card.trueName,"zh_CN"):len() % 2 == 1 then
                                return  true
                            elseif player:getSwitchSkillState(self.name) == fk.SwitchYin and Fk:translate(card.trueName,"zh_CN"):len() % 2 == 0 then
                                return true
                            end
                        end
                    end
                end
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if player:getSwitchSkillState(self.name,true) == fk.SwitchYang then
            player:drawCards(1,self.name)
        else
            room:askForGuanxing(player, room:getNCards(1, "top"), nil, nil)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_chenshiqilu"] = "塵世棋路",
    [":mcdh_chenshiqilu"] = "转换技，① 当你失去一张牌名字数为单数的牌后，你可以摸一张牌；② 当你失去一张牌名字数为双数的牌后，你可以卜算1。",
}

return chenshiqilu